<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>OpenFOAM 中的热物理类之接口 | Giskard&#39;s CFD Learning Tricks</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="本系列来看一下 OpenFOAM 中的热物理类。热物理类比较繁杂，这里先看一下纯物质的热物理模型。本篇先来看看热物理类在求解器中的接口，以2.3.x 版的 twoPhaseEulerFoam 为例。">
<meta property="og:type" content="article">
<meta property="og:title" content="OpenFOAM 中的热物理类之接口">
<meta property="og:url" content="http://xiaopingqiu.github.io/2016/06/25/thermophysics1/index.html">
<meta property="og:site_name" content="Giskard's CFD Learning Tricks">
<meta property="og:description" content="本系列来看一下 OpenFOAM 中的热物理类。热物理类比较繁杂，这里先看一下纯物质的热物理模型。本篇先来看看热物理类在求解器中的接口，以2.3.x 版的 twoPhaseEulerFoam 为例。">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="OpenFOAM 中的热物理类之接口">
<meta name="twitter:description" content="本系列来看一下 OpenFOAM 中的热物理类。热物理类比较繁杂，这里先看一下纯物质的热物理模型。本篇先来看看热物理类在求解器中的接口，以2.3.x 版的 twoPhaseEulerFoam 为例。">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

##ga('create', '[object Object]', 'auto');
ga('create', 'UA-62501686-1', 'auto');
ga('send', 'pageview');

</script>
<!-- End Google Analytics -->


</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Giskard&#39;s CFD Learning Tricks</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">CFD and Scientific Computing</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
          <a class="main-nav-link" href="/atom.xml">Rss</a>
        
          <a class="main-nav-link" href="/about">About</a>
        
      </nav>
      <nav id="sub-nav">
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="q" value="site:http://xiaopingqiu.github.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-thermophysics1" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/06/25/thermophysics1/" class="article-date">
  <time datetime="2016-06-25T06:27:14.000Z" itemprop="datePublished">2016-06-25</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/OpenFOAM/">OpenFOAM</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      OpenFOAM 中的热物理类之接口
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>本系列来看一下 OpenFOAM 中的热物理类。热物理类比较繁杂，这里先看一下纯物质的热物理模型。本篇先来看看热物理类在求解器中的接口，以2.3.x 版的 <code>twoPhaseEulerFoam</code> 为例。</p>
<a id="more"></a>
<p><code>twoPhaseEulerFoam</code> 中的热物理类的接口在 <code>phaseModel</code> 类中声明：<br><figure class="highlight lisp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">//- Thermophysical properties</span><br><span class="line">autoPtr&lt;rhoThermo&gt; thermo_<span class="comment">;</span></span><br><span class="line"></span><br><span class="line">thermo_<span class="list">(<span class="keyword">rhoThermo</span>:<span class="keyword">:New</span><span class="list">(<span class="keyword">fluid</span>.mesh<span class="list">()</span>, name_)</span>)</span></span><br></pre></td></tr></table></figure></p>
<p>可见，接口是 <code>rhoThermo</code> 类的指针。</p>
<p>接着看 <code>rhoThermo</code> 类的 <code>New</code> 函数。<br><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//- Selector</span></span><br><span class="line"><span class="keyword">static</span> autoPtr&lt;rhoThermo&gt; <span class="keyword">New</span></span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> fvMesh&amp;,</span><br><span class="line">    <span class="keyword">const</span> word&amp; phaseName=word::null</span><br><span class="line">);</span><br><span class="line">    </span><br><span class="line">Foam::autoPtr&lt;Foam::rhoThermo&gt; Foam::rhoThermo::New</span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> fvMesh&amp; mesh,</span><br><span class="line">    <span class="keyword">const</span> word&amp; phaseName</span><br><span class="line">)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span> basicThermo::New&lt;rhoThermo&gt;(mesh, phaseName);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这里调用的是 <code>basicThermo</code> 类的 <code>New</code> 函数。 这里先提一下继承关系，后面再细说：<code>rhoThermo</code> 类继承自 <code>fluidThermo</code> ， <code>fluidThermo</code> 类继承自 <code>basicThermo</code>。</p>
<figure class="highlight nimrod"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">//- <span class="type">Generic</span> <span class="type">New</span> <span class="keyword">for</span> each <span class="keyword">of</span> the related thermodynamics packages</span><br><span class="line">// basicThermo.C</span><br><span class="line"></span><br><span class="line"><span class="keyword">template</span>&lt;class <span class="type">Thermo</span>&gt;</span><br><span class="line"><span class="keyword">static</span> autoPtr&lt;<span class="type">Thermo</span>&gt; <span class="type">New</span></span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> fvMesh&amp;,</span><br><span class="line">    <span class="keyword">const</span> word&amp; phaseName=word::null</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">template</span>&lt;class <span class="type">Thermo</span>&gt;</span><br><span class="line"><span class="type">Foam</span>::autoPtr&lt;<span class="type">Thermo</span>&gt; <span class="type">Foam</span>::basicThermo::<span class="type">New</span></span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> fvMesh&amp; mesh,</span><br><span class="line">    <span class="keyword">const</span> word&amp; phaseName</span><br><span class="line">)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">IOdictionary</span> thermoDict</span><br><span class="line">    (</span><br><span class="line">        <span class="type">IOobject</span></span><br><span class="line">        (</span><br><span class="line">            phasePropertyName(dictName, phaseName),</span><br><span class="line">            mesh.time().constant(),</span><br><span class="line">            mesh,</span><br><span class="line">            <span class="type">IOobject</span>::<span class="type">MUST_READ_IF_MODIFIED</span>,</span><br><span class="line">            <span class="type">IOobject</span>::<span class="type">NO_WRITE</span>,</span><br><span class="line">            <span class="literal">false</span></span><br><span class="line">        )</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    typename <span class="type">Thermo</span>::fvMeshConstructorTable::<span class="keyword">iterator</span> cstrIter =</span><br><span class="line">        lookupThermo&lt;<span class="type">Thermo</span>, typename <span class="type">Thermo</span>::fvMeshConstructorTable&gt;</span><br><span class="line">        (</span><br><span class="line">            thermoDict,</span><br><span class="line">            <span class="type">Thermo</span>::fvMeshConstructorTablePtr_</span><br><span class="line">        );</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> autoPtr&lt;<span class="type">Thermo</span>&gt;(cstrIter()(mesh, phaseName));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>根据 RTS 机制的惯例， <code>New</code> 函数的功能是模型选择(<code>selector</code>)，即根据用户指定的关键字来选择对应的模型。 <code>New</code> 函数中先定义了一个 <code>IOdictionary</code> 类的对象， <code>thermoDict</code>，这个对象对应的正是热物理类的配置文件 <code>thermophysicalProperties</code>。<code>New</code> 函数里调用了 <code>lookupThermo</code> 函数，这个函数是关键：<br><figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// basicThermoTemplates.C</span></span><br><span class="line">template&lt;<span class="keyword">class</span> Thermo, <span class="keyword">class</span> <span class="keyword">Table</span>&gt;</span><br><span class="line">typename <span class="keyword">Table</span>::iterator Foam::basicThermo::lookupThermo</span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> dictionary&amp; thermoDict,</span><br><span class="line">    <span class="keyword">Table</span>* tablePtr</span><br><span class="line">)</span><br><span class="line">&#123;</span><br><span class="line">    word thermoTypeName;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (thermoDict.isDict(<span class="string">"thermoType"</span>))</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">const</span> dictionary&amp; thermoTypeDict(thermoDict.subDict(<span class="string">"thermoType"</span>));</span><br><span class="line"></span><br><span class="line">        Info&lt;&lt; <span class="string">"Selecting thermodynamics package "</span> &lt;&lt; thermoTypeDict &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">const</span> int nCmpt = 7;</span><br><span class="line">        <span class="keyword">const</span> <span class="keyword">char</span>* cmptNames[nCmpt] =</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="string">"type"</span>,</span><br><span class="line">            <span class="string">"mixture"</span>,</span><br><span class="line">            <span class="string">"transport"</span>,</span><br><span class="line">            <span class="string">"thermo"</span>,</span><br><span class="line">            <span class="string">"equationOfState"</span>,</span><br><span class="line">            <span class="string">"specie"</span>,</span><br><span class="line">            <span class="string">"energy"</span></span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// Construct the name of the thermo package from the components</span></span><br><span class="line">        thermoTypeName =</span><br><span class="line">            <span class="literal">word</span>(thermoTypeDict.<span class="keyword">lookup</span>(<span class="string">"type"</span>)) + '&lt;'</span><br><span class="line">          + <span class="literal">word</span>(thermoTypeDict.<span class="keyword">lookup</span>(<span class="string">"mixture"</span>)) + '&lt;'</span><br><span class="line">          + <span class="literal">word</span>(thermoTypeDict.<span class="keyword">lookup</span>(<span class="string">"transport"</span>)) + '&lt;'</span><br><span class="line">          + <span class="literal">word</span>(thermoTypeDict.<span class="keyword">lookup</span>(<span class="string">"thermo"</span>)) + '&lt;'</span><br><span class="line">          + <span class="literal">word</span>(thermoTypeDict.<span class="keyword">lookup</span>(<span class="string">"equationOfState"</span>)) + '&lt;'</span><br><span class="line">          + <span class="literal">word</span>(thermoTypeDict.<span class="keyword">lookup</span>(<span class="string">"specie"</span>)) + <span class="string">"&gt;&gt;,"</span></span><br><span class="line">          + <span class="literal">word</span>(thermoTypeDict.<span class="keyword">lookup</span>(<span class="string">"energy"</span>)) + <span class="string">"&gt;&gt;&gt;"</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// Lookup the thermo package</span></span><br><span class="line">        typename <span class="keyword">Table</span>::iterator cstrIter = tablePtr-&gt;find(thermoTypeName);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// Print error message if package not found in the table</span></span><br><span class="line">        <span class="keyword">if</span> (cstrIter == tablePtr-&gt;end())</span><br><span class="line">        &#123;</span><br><span class="line">            FatalErrorIn(Thermo::typeName + <span class="string">"::New"</span>)</span><br><span class="line">                &lt;&lt; <span class="string">"Unknown "</span> &lt;&lt; Thermo::typeName &lt;&lt; <span class="string">" type "</span> &lt;&lt; <span class="keyword">nl</span></span><br><span class="line">                &lt;&lt; <span class="string">"thermoType"</span> &lt;&lt; thermoTypeDict &lt;&lt; <span class="keyword">nl</span> &lt;&lt; <span class="keyword">nl</span></span><br><span class="line">                &lt;&lt; <span class="string">"Valid "</span> &lt;&lt; Thermo::typeName &lt;&lt; <span class="string">" types are:"</span> &lt;&lt; <span class="keyword">nl</span> &lt;&lt; <span class="keyword">nl</span>;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// Get the list of all the suitable thermo packages available</span></span><br><span class="line">            wordList validThermoTypeNames</span><br><span class="line">            (</span><br><span class="line">                tablePtr-&gt;sortedToc()</span><br><span class="line">            );</span><br><span class="line"></span><br><span class="line">            <span class="comment">// Build a table of the thermo packages constituent parts</span></span><br><span class="line">            <span class="comment">// Note: row-0 contains the names of constituent parts</span></span><br><span class="line">            <span class="keyword">List</span>&lt;wordList&gt; validThermoTypeNameCmpts</span><br><span class="line">            (</span><br><span class="line">                validThermoTypeNames.size() + 1</span><br><span class="line">            );</span><br><span class="line"></span><br><span class="line">            validThermoTypeNameCmpts[0].setSize(nCmpt);</span><br><span class="line">            forAll(validThermoTypeNameCmpts[0], j)</span><br><span class="line">            &#123;</span><br><span class="line">                validThermoTypeNameCmpts[0][j] = cmptNames[j];</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// Split the thermo package names into their constituent parts</span></span><br><span class="line">            forAll(validThermoTypeNames, i)</span><br><span class="line">            &#123;</span><br><span class="line">                validThermoTypeNameCmpts[i+1] =</span><br><span class="line">                    Thermo::splitThermoName(validThermoTypeNames[i], nCmpt);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// Print the table of available packages</span></span><br><span class="line">            <span class="comment">// in terms of their constituent parts</span></span><br><span class="line">            printTable(validThermoTypeNameCmpts, FatalError);</span><br><span class="line"></span><br><span class="line">            FatalError&lt;&lt; <span class="keyword">exit</span>(FatalError);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> cstrIter;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        thermoTypeName = <span class="literal">word</span>(thermoDict.<span class="keyword">lookup</span>(<span class="string">"thermoType"</span>));</span><br><span class="line"></span><br><span class="line">        Info&lt;&lt; <span class="string">"Selecting thermodynamics package "</span> &lt;&lt; thermoTypeName &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">        typename <span class="keyword">Table</span>::iterator cstrIter = tablePtr-&gt;find(thermoTypeName);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (cstrIter == tablePtr-&gt;end())</span><br><span class="line">        &#123;</span><br><span class="line">            FatalErrorIn(Thermo::typeName + <span class="string">"::New"</span>)</span><br><span class="line">                &lt;&lt; <span class="string">"Unknown "</span> &lt;&lt; Thermo::typeName &lt;&lt; <span class="string">" type "</span></span><br><span class="line">                &lt;&lt; thermoTypeName &lt;&lt; <span class="keyword">nl</span> &lt;&lt; <span class="keyword">nl</span></span><br><span class="line">                &lt;&lt; <span class="string">"Valid "</span> &lt;&lt; Thermo::typeName &lt;&lt; <span class="string">" types are:"</span> &lt;&lt; <span class="keyword">nl</span></span><br><span class="line">                &lt;&lt; tablePtr-&gt;sortedToc() &lt;&lt; <span class="keyword">nl</span></span><br><span class="line">                &lt;&lt; <span class="keyword">exit</span>(FatalError);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> cstrIter;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>可见， <code>loopupThermo</code> 分两种情况处理，一种是 <code>thermophysicalProperties</code> 文件里有一个名为 <code>thermoType</code> 的 <code>subdict</code>，例如<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">thermoType</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="title">type</span>            heRhoThermo;</span><br><span class="line">    <span class="title">mixture</span>         pureMixture;</span><br><span class="line">    <span class="title">transport</span>       const;</span><br><span class="line">    <span class="title">thermo</span>          hConst;</span><br><span class="line">    <span class="title">equationOfState</span> perfectGas;</span><br><span class="line">    <span class="title">specie</span>          specie;</span><br><span class="line">    <span class="title">energy</span>          sensibleInternalEnergy;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这种情况下， <code>subdict</code> 里的 7 个关键字将逐一读入，最终将合并起来，得到一个字符串，并赋值给 <code>thermoTypeName</code><br>以上面的那种情况为例，最终得到的<code>thermoTypeName</code> 为<br><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">heRhoThermo&lt;pureMixture&lt;const&lt;hConst&lt;perfectGas&lt;specie<span class="prompt">&gt;&gt;</span>,sensibleInternalEnergy&gt;&gt;&gt;</span><br></pre></td></tr></table></figure></p>
<p>然后，根据这个关键词，从 hashTable 中找到对应的元素。如果找不到对应的，则报错，并输出所有可选的方案(由 <code>splitThermoName</code> 和 <code>printTable</code> 两个函数完成，细节这里暂且不表)。</p>
<p>另一种情况，直接从 <code>thermophysicalProperties</code> 读取 <code>thermoType</code> 对应的字符串并赋值给 <code>thermoTypeName</code>，然后据此来从 hashTable 中找到对应的元素。</p>
<p>OpenFOAM 自带的算例中，<code>thermophysicalProperties</code> 文件绝大部分采用前一种方式，因为更直观。后一种方式我在 OpenFOAM-2.3.x 版中只找到一个例子：tutorials/mesh/foamyQuadMesh/OpenCFD/constant/thermophysicalProperties<br><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">thermoType      hePsiThermo&lt;pureMixture&lt;const&lt;hConst&lt;perfectGas&lt;specie<span class="prompt">&gt;&gt;</span>,sensibleEnthalpy&gt;&gt;&gt;;</span><br></pre></td></tr></table></figure></p>
<p>至此，大致就知道热物理类的接口定义是怎么回事了。但是，这个存储了可选模型的 hashTable 里有哪些内容，又是怎么构建起来的，还有待进一步深入探索。另外，从 <code>thermoType</code> 对应的字符串的样式，能猜到最终热物理类的接口 <code>thermo_</code> 指向的可能是类似 <code>heRhoThermo</code> 类的对象，而且这些类多半是模板类，并有着复杂的继承派生关系，这部分也还有待深入探索。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://xiaopingqiu.github.io/2016/06/25/thermophysics1/" data-id="cj2lay323001tkkmbc9116hwv" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Code-Explained/">Code Explained</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/thermophysicalModels/">thermophysicalModels</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2016/06/25/thermophysics2/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          OpenFOAM 中的热物理类之 hashTable 的创建
        
      </div>
    </a>
  
  
    <a href="/2016/05/22/QAndLambda/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">涡结构提取</div>
    </a>
  
</nav>

  
</article>


<section id="comments">
  <!-- 多说评论框 start -->
  <div class="ds-thread" data-thread-key="post-thermophysics1" data-title="OpenFOAM 中的热物理类之接口" data-url="http://xiaopingqiu.github.io/2016/06/25/thermophysics1/"></div>
  <!-- 多说评论框 end -->
  <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
  <script type="text/javascript">
  var duoshuoQuery = {short_name:"xiaopingqiu"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
  <!-- 多说公共JS代码 end -->
</section>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/C/">C++</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/DEM/">DEM</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/OpenFOAM/">OpenFOAM</a><span class="category-list-count">44</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Paraview/">Paraview</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/swak4Foam/">swak4Foam</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/test/">test</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/vim/">vim</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Boundary-conditions/">Boundary conditions</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/">C++</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CentOS/">CentOS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Code-Explained/">Code Explained</a><span class="tag-list-count">29</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LES/">LES</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LIGGGHTS/">LIGGGHTS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ODE/">ODE</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OpenFOAM/">OpenFOAM</a><span class="tag-list-count">20</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Postprocessing/">Postprocessing</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Preprocessing/">Preprocessing</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RTS/">RTS</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TIL/">TIL</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Windows/">Windows</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fvOptions/">fvOptions</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovyBC/">groovyBC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/paraview/">paraview</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/test/">test</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/thermophysicalModels/">thermophysicalModels</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/turbulence-model/">turbulence model</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wall-functions/">wall functions</a><span class="tag-list-count">4</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Boundary-conditions/" style="font-size: 15.56px;">Boundary conditions</a><a href="/tags/C/" style="font-size: 11.11px;">C++</a><a href="/tags/CentOS/" style="font-size: 10px;">CentOS</a><a href="/tags/Code-Explained/" style="font-size: 20px;">Code Explained</a><a href="/tags/LES/" style="font-size: 10px;">LES</a><a href="/tags/LIGGGHTS/" style="font-size: 10px;">LIGGGHTS</a><a href="/tags/ODE/" style="font-size: 10px;">ODE</a><a href="/tags/OpenFOAM/" style="font-size: 18.89px;">OpenFOAM</a><a href="/tags/Postprocessing/" style="font-size: 17.78px;">Postprocessing</a><a href="/tags/Preprocessing/" style="font-size: 11.11px;">Preprocessing</a><a href="/tags/RTS/" style="font-size: 12.22px;">RTS</a><a href="/tags/TIL/" style="font-size: 10px;">TIL</a><a href="/tags/Windows/" style="font-size: 10px;">Windows</a><a href="/tags/fvOptions/" style="font-size: 11.11px;">fvOptions</a><a href="/tags/groovyBC/" style="font-size: 10px;">groovyBC</a><a href="/tags/paraview/" style="font-size: 10px;">paraview</a><a href="/tags/test/" style="font-size: 11.11px;">test</a><a href="/tags/thermophysicalModels/" style="font-size: 14.44px;">thermophysicalModels</a><a href="/tags/turbulence-model/" style="font-size: 16.67px;">turbulence model</a><a href="/tags/vim/" style="font-size: 10px;">vim</a><a href="/tags/wall-functions/" style="font-size: 13.33px;">wall functions</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/">五月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">四月 2016</a><span class="archive-list-count">12</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">三月 2016</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">十二月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">十一月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">十月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">九月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">八月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/06/">六月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/">五月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/04/">四月 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/05/12/duoshuoAnnouncement/">多说评论系统将停止提供服务</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewScritps/">Paraview 脚本一例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCamera/">Paraview 中有关 Camera 的操作两例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCustomFilter/">Paraview 中创建 Custom Filter</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewStreamLineOnSlice/">在 Paraview 中画截面上的流线</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Giskard Q.<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

<script src="//dn-lbstatics.qbox.me/lbservice/busuanzi/2.0/busuanzi.mini.js"/></script>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/atom.xml" class="mobile-nav-link">Rss</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-62501686-1', 'auto');
  ga('send', 'pageview');

</script>

  </div>
<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</body>
</html>